<template>
	<view class="pd pt20  pm10 bgff display-flex fxxcvxcrtr">
		<view class=" flex-1 pr">
			<icon type="search" class="skjjxcerert" size="22"></icon>
			<input type="text" confirm-type="search" v-model="queryLike" @confirm="hf('gwList?queryLike='+queryLike)"
				class="xjhsddfr" placeholder="请输入关键词进行搜索" />
		</view>
		<view class="ml20 pr">
			<icon class="iconfont icon-fenxiang fz36 cz z6"></icon>
			<button type="default" open-type="share" class="xzcdfrtrt"></button>
		</view>
	</view>

	<view class="pd bgff pm10">
		<view class="">
			<swiper indicator-active-color="#fff" class="xzcxzcdftr" circular :indicator-dots="true" :autoplay="true"
				:interval="3000" :duration="1000">
				<swiper-item class="w100 h100" v-for="sd in bannersf" @tap="xczxcdfsf(sd.remark)">
					<frImage :src="sd.dictValue" class="w100 h100 cz"></frImage>
				</swiper-item>
			</swiper>
		</view>
	</view>
	<view class=" display-flex pd ye dfdcxzfrtrey pt10 pm10">
		<view class=" vertical-center">
			<icon class="iconfont icon-gonggao ye cz dfdftrtytrey"></icon>
		</view>
		<view class="flex-1 vertical-center  ml20 fz24">

			<swiper circular vertical class="w100 h100" :autoplay="true" :interval="3000" :duration="1000">
				<swiper-item class="w100 h100 vertical-center tl" v-for="sd in xmfxc">
					<view class="w100 ">
						{{transferTxerMD(sd.noticeTime)}} {{sd.msg}}
					</view>
				</swiper-item>
			</swiper>
		</view>
	</view>

	<view class="kjxczxcretx bgff cen pt20 pm20">
		<template v-for="item in kmxczxcd">
			<view v-if="item.remark" class="" @tap="hf('gwList?title='+item.dictLabel+'&dictValue='+item.dictValue)">
				<view class="xcxztrr vertical-center">
					<icon class="iconfont  ls" :class="item.remark"></icon>
				</view>
				<view class="z9 fz24 ">
					{{item.dictLabel}}
				</view>
			</view>
		</template>

	</view>
	<view class="bgff pm20 pd display-flex">
		<view class="flex-1 mr10" @tap="hf('postArea')">
			<view class="xczxsertexcr pd display-flex">
				<view class="fz32 cf vertical-center flex-1 tl">
					<view class="">
						<view class="">
							热门岗位
						</view>
						<view class="">
							职等你来
						</view>
					</view>
				</view>
				<view class=" vertical-center pr10">
					<icon class="iconfont icon-huo cf fz70 cz"></icon>
				</view>
			</view>
		</view>
		<view class="flex-1 ml10" @tap="hf('enterprises')">
			<view class="xczxsertexcr pd display-flex ab">
				<view class="fz32 cf vertical-center flex-1 tl">
					<view class="">
						<view class="">
							名企直聘
						</view>
						<view class="">
							高薪福利
						</view>
					</view>
				</view>
				<view class=" vertical-center pr10">
					<icon class="iconfont icon-gongsiguanli cf fz70 cz"></icon>
				</view>
			</view>
		</view>
	</view>

	<view class="pt20 pm20 pl20 display-flex">
		<view class="xczczxfd pd pt20 pm20 bgff " @tap="hf('/pages/enterprise/list')">
			<view class="fz28">
				名企优聘
			</view>
			<view class="fz22 ls pr mt5">

				更多内容 <icon class="iconfont icon-rightyou fz22 xcxzcrfetxe"></icon>


			</view>
		</view>
		<view class="flex-1">
			<swiper class="h100" circular :autoplay="true" :interval="3000" :duration="1000">
				<swiper-item class="w100 h100" v-for="sd in jmxcdf">
					<view class="display-flex">
						<view v-for="item in sd" @tap="hf('/pages/enterprise/details?id='+item.id)"
							class="flex-1 ml20 display-flex xczczxfd pl10 pt10 pm10  bgff ">
							<view class="">
								<image :src="item.companyImg" class="xczxstrxcr cz"></image>
							</view>
							<view class="ml10 vertical-center">
								<view class="">
									<view class="fz28 dian fgxcxtr">
										{{item.companyName}}
									</view>
									<view class="fz22 ls pr mt5">
										优质岗位{{item.jobNum}}个

									</view>
								</view>
							</view>
						</view>
					</view>
				</swiper-item>
			</swiper>
		</view>
	</view>
	<view class="pr">
		<view class="bgff btm pd pm20  gfvcxrtrtytryu pr pt20" id="xcxzresx">
			<view class="  display-flex cen">
				<view class="flex-1 fz26 " @tap="xcvcxtryyt">
					<picker @change="jjxcza" :range="arraya">
						<view class="vertical-center">
							<view class="display-flex">
								<view class=" ">
									<view class="dsfxcvtrt dian ab">
										<text class="cz">{{arraya[unxczfa]||'推荐'}}</text>
									</view>
								</view>
								<view class="vertical-center ">
									<text class="iconfont icon-down fz24 ml10 kmxczxrt"></text>
								</view>
							</view>
						</view>
					</picker>
				</view>

				<view class="flex-1 fz26 display-flex" @tap="quyhzxczxre">
					<view class=" ">
						<view class="dsfxcvtrt dian">
							<text class="cz">{{unxczfb||'区域选择'}}</text>
						</view>
					</view>
					<view class="vertical-center ">
						<text class="iconfont icon-down fz24 ml10 kmxczxrt"></text>
					</view>
				</view>
				<view class="flex-1 fz26 " @tap="xcvcxtryyt">
					<picker @change="jjxczc" :range="arrayc">
						<view class="vertical-center">
							<view class="display-flex">
								<view class=" ">
									<view class="dsfxcvtrt dian ">
										<text class="cz">{{arrayc[unxczfc]||'企业选择'}}</text>
									</view>

								</view>
								<view class="vertical-center ">
									<text class="iconfont icon-down fz24 ml10 kmxczxrt"></text>
								</view>
							</view>
						</view>
					</picker>
				</view>
				<view class="flex-1 fz26 " @tap="xcvcxtryyt">
					<picker @change="jjxczd" :range="arrayd">
						<view class="vertical-center">
							<view class="display-flex">
								<view class=" ">
									<view class="dsfxcvtrt dian ">
										<text class="cz">{{arrayd[unxczfd]||'工作类型'}}</text>
									</view>

								</view>
								<view class="vertical-center ">
									<text class="iconfont icon-down fz24 ml10 kmxczxrt"></text>
								</view>
							</view>
						</view>
					</picker>
				</view>
			</view>

			<view class="kkxczretxdr btm" v-if="kmmxsd">
				<diquxz @success="hejmxdfrf"></diquxz>
			</view>
		</view>




		<zwList :kxzcxfdf="kxzcxfdf"></zwList>


		<view class="xczcfrstrt" v-if="kmmxsd">

		</view>
	</view>
	<view class="kedusdf vertical-center">
		<icon class="iconfont icon-kefu cf fz60 cz"></icon>
		<button type="default" open-type="contact" class="xczxcrtrexer"></button>
	</view>
</template>
<script lang="ts" setup>
	import { ref } from "vue"
	import { hf, hfer, hfsan, dxrequest, zidianall, transferTxerMD, caifen } from "@/util/index.js"
	import { wxlogin } from "@/util/dxwchar.js"
	import diquxz from "@/components/diquxz.vue"
	import zwList from "@/components/zwList.vue"
	import frImage from "@/components/fr-image/fr-image.vue"
	import {
		onLoad,
		onPageScroll,
		onShow,
		onShareAppMessage,
		onPullDownRefresh,
		onReachBottom
	} from "@dcloudio/uni-app";
	const list = ref([])
	const xczxdfrer = ref()
	const bannersf = ref([])
	const kmmxsd = ref()
	const jcdfsdf = ref()
	const arraya = ['推荐', '最新', '附近']
	const arrayc = ['全部']
	const xczrerx = ref()
	const arrayd = ['全部']
	const unxczfa = ref()
	const unxczfb = ref("区域选择")
	const unxczfc = ref("企业选择")
	const unxczfd = ref("工作类型")
	const page = ref(1)
	const kxzcxfdf = ref([])
	const xmfxc = ref([])
	const kmxczxcd = ref([])
	const jmxcdf = ref([])
	const queryLike = ref()
	const wzinfo = ref({})
	const jnxcfd = ref({
		orderField: "t.is_good",
		order: "desc"
	})
	const jmxcfb = ref({})
	const companyId = ref()
	const type = ref()
	uni.removeStorageSync("jd")
	const userId = uni.getStorageSync("userId")
	const jkxczxcd = ref()
	const inhsd = async () => {
		const { data } = await dxrequest("/api/notice/page?limit=20&order=&orderField=&page=1&type=6")
		xmfxc.value = data.list
	}
	const jjxcza = (data) => {
		unxczfa.value = data.detail.value
		jnxcfd.value = {}
		if (data.detail.value == 1) {
			jnxcfd.value.orderField = "t.create_time"
			jnxcfd.value.order = "desc"
		}
		if (data.detail.value == 0) {
			jnxcfd.value.orderField = "t.is_good"
			jnxcfd.value.order = "desc"
		}
		if (data.detail.value == 2) {
			jnxcfd.value.lng = wzinfo.value.lng
			jnxcfd.value.lat = wzinfo.value.lat
		}
		page.value = 1
		kxzcxfdf.value = []
		zhiweik()
	}
	const jjxczc = (data) => {
		unxczfc.value = data.detail.value
		if (data.detail.value > 0) {
			companyId.value = xczrerx.value[data.detail.value - 1].id
		} else {
			companyId.value = ""
		}
		page.value = 1
		kxzcxfdf.value = []
		zhiweik()
	}
	const jjxczd = (data) => {
		unxczfd.value = data.detail.value

		if (data.detail.value > 0) {
			type.value = kmxczxcd.value[data.detail.value - 1].dictValue
		} else {
			type.value = ""
		}
		page.value = 1
		kxzcxfdf.value = []
		zhiweik()
	}
	const quyhzxczxre = () => {
		uni.pageScrollTo({
			selector: "#xcxzresx"
		})
		kmmxsd.value = true
	}
	const xcvcxtryyt = () => {
		uni.pageScrollTo({
			selector: "#xcxzresx"
		})
	}
	const getcsList = async () => {
		const { data } = await dxrequest("/api/tmcompany/option")
		data.map(a => {
			arrayc.push(a.name)
		})
		xczrerx.value = data
	}
	const hejmxdfrf = (data) => {
		kmmxsd.value = false
		unxczfb.value = data
		const obj = data.split("/")
		jmxcfb.value = {}
		if (obj[0] != '全部省' && obj[0]) {
			jmxcfb.value.province = obj[0]
		}
		if (obj[1] != '全部市' && obj[1]) {
			jmxcfb.value.city = obj[1]
		}
		if (obj[2] != '全部区"' && obj[2]) {
			jmxcfb.value.county = obj[2]
		}
		page.value = 1
		kxzcxfdf.value = []
		zhiweik()
	}
	const zhiweik = async () => {
		const { data } = await dxrequest("/api/job/page", {
			limit: 10,
			page: page.value,
			...jmxcfb.value,
			...jnxcfd.value,
			companyId: companyId.value,
			type: type.value
		})
		data.list.map(a => {
			kxzcxfdf.value.push(a)
		})
		// kxzcxfdf.value = data.list
		uni.stopPullDownRefresh();
	}


	const kxczdf = async () => {
		jmxcdf.value = []
		const { data } = await dxrequest("/api/tmcompany/listByType", {
			limit: 9
		})

		for (let i = 0; i < data.list.length; i += 2) {
			jmxcdf.value.push(data.list.slice(i, i + 2));
		}
	}



	onLoad(async (data) => {
		let jmxxd = uni.getStorageSync("openid")
		const scene = decodeURIComponent(data.scene)
		let inviteUserId = data.inviteUserId || uni.getStorageSync("inviteUserId")
		if (data.inviteUserId) {
			uni.setStorageSync("inviteUserId", inviteUserId)
		}
		const banner = await zidianall("banner_img")
		bannersf.value = banner
		kmxczxcd.value = await zidianall("job_type")
		kmxczxcd.value.map(a => {
			try {
				arrayd.push(a.dictLabel)
			} catch (e) {

			}
		})

		inhsd()
		kxczdf()
		zhiweik()
		getcsList()
		if (!uni.getStorageSync("openid")) {
			const { openid } = await wxlogin()
			uni.setStorageSync("openid", openid)
			jmxxd = openid
		}

		if (scene != 'undefined') {
			try {
				inviteUserId = scene
				if (inviteUserId && inviteUserId != "undefined") {
					uni.setStorageSync("inviteUserId", inviteUserId)
					jkxczxcd.value = { inviteUserId, userId }
					if (inviteUserId != userId) {
						await dxrequest("/api/userinvite", {
							inviteUserId,
							userId,
							openId: jmxxd
						}, "post")
					}

				}
			} catch (e) {

			}
		} else if (inviteUserId) {
			if (inviteUserId != userId) {
				await dxrequest("/api/userinvite", {
					inviteUserId: inviteUserId,
					userId,
					openId: jmxxd
				}, "post")
			}


		}

		try {
			uni.getLocation({
				type: 'wgs84',
				success: function (res) {
					wzinfo.value.lng = res.longitude
					wzinfo.value.lat = res.latitude
				}
			});
		} catch (e) {

		}
		const xcxrty = await dxrequest("/api/user/" + jmxxd, { node: 1 })
		try{
			uni.setStorageSync("userId", xcxrty.data.id)
		}catch(e){
			
		}

	})
	onReachBottom(() => {
		page.value++
		zhiweik()
	})
	onShareAppMessage(() => {
		return {
			title: '薪智直聘',
			path: '/pages/index/index'
		}
	})
	onPullDownRefresh(() => {
		page.value = 1
		kxzcxfdf.value = []
		inhsd()
		kxczdf()
		zhiweik()
		getcsList()
	})
	const xczxcdfsf = (remark) => {
		const kzxcdf = encodeURIComponent(remark)
		hf('/pages/webview?urls=' + kzxcdf)
	}
</script>

<style scoped>
	.xzcxzcdftr {
		height: 290rpx;
		border-radius: 10rpx;
		overflow: hidden;
	}

	.dfdcxzfrtrey {
		background: #FFF6E4;
	}

	.dfdftrtytrey {
		position: relative;
		bottom: 6rpx;
	}

	.kjxczxcretx {
		display: grid;
		grid-template-columns: repeat(5, 1fr);
		grid-template-rows: repeat(1, 1fr);
		grid-column-gap: 20rpx;
		grid-row-gap: 20rpx
	}

	.xcxztrr {
		height: 80rpx;
	}
</style>